<template>
<view>
	<!--聊天信息 -->
	
	<view class="content">
		<view class="title">群聊成员</view>
		
		<view class="user-box">
			<view class="item" v-for="(item,index) in data.userlist" :key="index">
				<image 
				:src="item.avatar"
				class="avatar"
				mode="aspectFill"
				></image>
				
				<view class="nickname text-cut">{{item.nickname || ''}}</view>
			</view>
			
			<view class="item add-box" @click="$wanlshop.to('/pages/new/addFriend?group_id='+group_id)">+</view>
			<view class="item add-box" @click="$wanlshop.to('/pages/new/reduceFriend?group_id='+group_id)">-</view>
		</view>
		
		<view class="flex align-center justify-center w100">
			<view class="flex align-center" @click="$wanlshop.to('/pages/new/viewFriend?group_id='+group_id)">
				<text class="more-title">查看{{data.user_total}}名群成员</text>
				<view class="wlIcon-fanhui2 colorgrey"></view>
			</view>
		</view>
	</view>
	
	<view class="item-box">
		<view class="title2">群聊名称</view>
		<view class="flex align-center" @click="openMadal()">
			<text class="chat-name text-cut">{{data.name || ''}}</text>
			<view class="wlIcon-fanhui2 colorgrey"></view>
		</view>
	</view>
	
	<view class="fixed-btn">
		<view class="btn" @click="quitGroup()">退出群聊</view>
		<view class="btn mt20" v-if="data.is_del" @click="delGroup()">删除群聊</view>
	</view>
	
	
	<wanl-modal custom :show="showModal" width="93%" padding="0rpx">
		<view class="modal-body">
			<image src="/static/images/modal_bg.png" class="modalImage"></image>
			<view class="modal-box">
				<view class="flex align-center justify-center pb50">
					<view class="modal-title">修改群名称</view>
					<image src="/static/images/close.png" class="close-image" @click="closeModel"></image>
				</view>
				
				<view class="input-box">
					<view class="input-title">群聊名称</view>
					<input placeholder="请输入群聊名称" 
					placeholder-style='text-align:right;font-size: 26rpx;'
					v-model="name"
					></input>
				</view>
				
				<view class="pay-btn" @click="modifyName()">确认</view>
				
			</view>
		</view>
	</wanl-modal>
	
</view>
	
</template>

<script>
export default {
	data() {
		return {
			data:{},
			group_id:0, //群聊ID
			showModal:false,
			name:'',
		}
	},
	onLoad(option) {
		if(option.group_id){
			this.group_id = option.group_id;
		}
		
		this.loadData();
	},
	methods: {
		async loadData() {
			await uni.request({
				url: '/im/groupshow',
				method: 'GET',
				data:{
					id: this.group_id,
				},
				success: res => {
					if(res.code == 1 || res.res.code == 1){
						this.data = res.data;
						this.name = res.data.name;
					}	
				}
			});
			
			uni.stopPullDownRefresh();
		},
		quitGroup(){
			uni.showModal({
				content: '确定要退出群聊？',
				success: res => {
					if (res.confirm) {
						uni.request({
							url: '/im/delgroup',
							method: 'POST',
							data: {
								id: this.group_id,
								type: 0,
							},
							success: del => {
								uni.switchTab({
									url: '/pages/chat'
								})
							}
						});
					}
				}
			});
		},
		delGroup(){
			uni.showModal({
				content: '确定要删除群聊？',
				success: res => {
					if (res.confirm) {
						uni.request({
							url: '/im/delgroup',
							method: 'POST',
							data: {
								id: this.group_id,
								type: 1,
							},
							success: del => {
								uni.switchTab({
									url: '/pages/chat'
								})
							}
						});
					}
				}
			});
		},
		openMadal(){
			this.showModal = true;
		},
		closeModel(){
			this.showModal = false;
		},
		modifyName(){
			if(!this.name){
				this.$wanlshop.msg('请输入群聊名称');
				return false;
			}
			
			uni.request({
				url: '/im/groupname',
				method: 'POST',
				data: {
					id: this.group_id,
					name: this.name,
				},
				success: res => {
					if(res.code == 1 || res.res.code == 1){
						this.$wanlshop.msg('修改成功');
						this.showModal = false;
						this.loadData();
					}else{
						this.$wanlshop.msg(res.msg);
					}
				}
			});
		}
	}
}	
</script>

<style lang="scss" scoped>
.content{
	margin: 20rpx 24rpx 20rpx 24rpx;
	background-color: #ffffff;
	border-radius: 20rpx;
	padding: 28rpx;
}	

.title{
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #292929;
}

.user-box{
	margin-top: 39rpx;
	margin-bottom: 39rpx;
	display: flex;
	justify-content: flex-start;
	flex-wrap: wrap;
}

.avatar{
	width: 64rpx;
	height: 64rpx;
	border-radius: 50%;
}

.nickname{
	font-size: 22rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #292929;
	margin-top: 15rpx;
	width: 86rpx;
}

.item{
	display: flex;
	flex-direction: column;
	margin-right: 56rpx;
	margin-top: 35rpx;
	align-items: center;
}

.item:nth-child(5n){
	margin-right: 0rpx !important;
}

.more-title{
	font-size: 26rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #999999;
}
.w100{
	width: 100%;
}

.item-box{
	background-color: #ffffff;
	border-radius: 20rpx;
	margin: 0rpx 24rpx 0rpx 24rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 36rpx 28rpx;
}

.title2{
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #292929;
}

.chat-name{
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #999999;
}

.colorgrey{
	color: #999999;
}

.btn{
	width: 702rpx;
	height: 88rpx;
	background: #ffffff;
	border-radius: 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #F53938;
}

.fixed-btn{
	display: flex;
	align-items: center;
	justify-content: center;
	position: fixed;
	bottom: 80rpx;
	left: 24rpx;
	flex-direction: column;
}

.add-box{
	width: 64rpx;
	height: 64rpx;
	background: #F7F7F7;
	border: 1rpx solid #EBEBEB;
	border-radius: 50%;
	color: #CCCCCC;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 40rpx;
}

.mt20{
	margin-top: 20rpx;
}

.modal-body{
	height: 738rpx;
	background-color: #FFFFFF;
	border-radius: 20rpx;
}

.modal-middle-title{
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 12rpx;
}

.modalImage{
	width: 698rpx;
	height: 204rpx;
}

.modal-box{
	position: absolute;
	top: 30rpx;
	left: 0rpx;
	width: 100%;
	padding-left: 28rpx;
	padding-right: 28rpx;
	padding-bottom: 28rpx;
}

.modal-title{
	font-size: 32rrpx;
	font-family: PingFang SC;
	font-weight: 700;
	color: #292929;
}

.close-image{
	width: 42rpx;
	height: 42rpx;
	position: absolute;
	top: 0rpx;
	right: 28rpx;
}

.modal-money{
	font-size: 24rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #292929;
	margin-top: 42rpx;
	margin-bottom: 27rpx;
}


.input-box{
	width: 646rpx;
	height: 88rpx;
	background: #FFFFFF;
	border: 1px solid #CCCCCC;
	border-radius: 20rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0rpx 32rpx;
	margin-bottom: 32rpx;
	
	input{
		text-align: right;
		width: 350rpx;
	}
}

.pay-btn{
	width: 646rpx;
	height: 88rpx;
	background: #366BEB;
	border-radius: 20rpx;
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #FFFFFF;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 64rpx;
}

.pb50{
	padding-bottom: 100rpx;
}

</style>